package com.jiusuzu.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jiusuzu.common.pojo.EUDataGridResult;
import com.jiusuzu.common.pojo.JiusuzuResult;
import com.jiusuzu.pojo.TbItemParam;
import com.jiusuzu.service.ItemParamService;

/**
 * 商品参数controller
 * 
 * @author 李锐洋
 */
@Controller
@RequestMapping("/item/param")
public class ItemParamController {

	@Autowired
	private ItemParamService itemParamService;

	/**
	 * 根据Cid查询该类目规格参数是否添加
	 * 
	 * @param itemCatId
	 * @return
	 */
	@RequestMapping("/query/itemcatid/{itemCatId}")
	@ResponseBody
	public JiusuzuResult getItemParamByCid(@PathVariable Long itemCatId) {
		JiusuzuResult result = itemParamService.getItemParamByCid(itemCatId);
		return result;
	}

	/**
	 * 根据Cid查询该类目规格参数是否添加
	 * 
	 * @param itemCatId
	 * @return
	 */
	@RequestMapping("/list")
	@ResponseBody
	public EUDataGridResult getItemParam(Integer page, Integer rows) {
		EUDataGridResult result = itemParamService.getItemList(page, rows);
		return result;
	}

	/**
	 * 保存未添加的商品类目的规格参数
	 * 
	 * @param cid
	 * @param paramData
	 * @return
	 */
	@RequestMapping("/save/{cid}")
	@ResponseBody
	public JiusuzuResult insertItemParam(@PathVariable Long cid, String paramData) {
		// 创建pojo对象
		TbItemParam itemParam = new TbItemParam();
		itemParam.setItemCatId(cid);
		itemParam.setParamData(paramData);
		JiusuzuResult result = itemParamService.insertItemParam(itemParam);
		return result;
	}
}
